﻿using System;
using System.Collections.Generic;
using System.Text;
using DCRF.Common.Connection;
using System.Windows.Forms;
using DCRF.Common.Interface;

namespace DCRF.BaseBlocks.Commander.Console.Nodes
{
    public class ConnectorNode: INode
    {
        public TreeNode myNode = null;
        public IBlockWeb myWeb = null;
        public Guid myId = Guid.Empty;  //if this is empty, refer to globalconnectors
        public string myConnectorKey = null;

        public ConnectorNode(TreeNode node, IBlockWeb web, Guid id, string key)
        {
            myNode = node;
            myWeb = web;
            myId = id;
            myConnectorKey = key;
            myNode.Tag = this;

            Refresh();
        }

        public object ProcessRequest(string serviceName, params object[] args)
        {
            if (serviceName == "REF")
            {
                Refresh();
            }
            else if (serviceName == "ADD")
            {
                int counter = (int)args[0];
                Connector c = args[1] as Connector;

                c.Raise("Item" + counter.ToString(), myWeb[myId][myConnectorKey]);
            }

            return null;
        }

        public List<string> Commands
        {
            get
            {
                List<string> result = new List<string>();
                result.Add("REF");
                result.Add("ADD");

                return result;
            }
        }

        public void Refresh()
        {
            myNode.Nodes.Clear();
            myNode.Text = myConnectorKey;

            TreeNode eps = new TreeNode();
            myNode.Nodes.Add(eps);

            //TODO: fix new EndPointsNode(eps, myWeb, myId, myConnectorKey);
        }

      
    }
}
